﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Log 系统日志操作相关类
/// </summary>
public class Log
{
    public int AutoID;
    public string Title;
    public string Content;
    public DateTime AddDate;
    public string UserName;
    public string Status;
	public Log()
	{        
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    public Log(int logID)
    {
        string sqlString = "select * from LOG where AUTOID=" + logID.ToString();
        DBOperation DBO = new DBOperation();
        SqlDataReader sdr = DBO.GetDataReader(sqlString);
        if (sdr.Read())
        {
            this.AutoID = logID;
            this.Title = sdr["TITLE"].ToString();
            this.Content = sdr["CONTENT"].ToString();
            this.UserName = sdr["USERNAME"].ToString();
            this.Status = sdr["STATUS"].ToString();
            this.AddDate = Convert.ToDateTime(sdr["ADDDATE"].ToString());
        }
        sdr.Close();
    }
    /// <summary>
    /// 添加系统日志
    /// </summary>
    /// <returns>成功返回true，否则返回false</returns>
    public Boolean AddLog()
    {
        this.Status ="0";
        string sqlString = "insert into LOG (TITLE,CONTENT,USERNAME,ADDDATE,STATUS) values ('";
        sqlString += this.Title + "','" + this.Content + "','" + this.UserName + "','" + this.AddDate.ToString()+ "','" + this.Status + "')";
        DBOperation DBO = new DBOperation();
        if (DBO.ExcuteSql(sqlString))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public Boolean UpdateLog()
    {        
        string sqlString = "update LOG set TITLE='"+this.Title+"',CONTENT='"+this.Content+"',USERNAME='"+this.UserName+"',ADDDATE='"+this.AddDate.ToString()+"',STATUS="+this.Status.ToString()+" where AUTOID="+this.AutoID;   
        DBOperation DBO = new DBOperation();
        if (DBO.ExcuteSql(sqlString))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public Boolean DelLog()
    {
        string sqlString = "delete from LOG where AUTOID=" + this.AutoID;
        DBOperation DBO = new DBOperation();
        if (DBO.ExcuteSql(sqlString))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
